import axios from 'axios'
import store from '@/store/index'
const request = axios.create({
  baseURL: 'http://hmmm-api.itheima.net'
})
// 请求拦截器
// http request 请求拦截器，有token值则配置上token值
const { user } = store.state
request.interceptors.request.use(
  config => {
    if (user && user.token) {
      config.headers.Authorization = `Bearer ${user.token}`
    }
    return config
  },
  err => {
    return Promise.reject(err)
  }
)
export default request
